Protecting a Field

Sometimes you don't want a user to be able to write into a field. Try activating the second field. Focus will quickly return to the first field.


Discussion

This protection system can be bypassed if you type quickly (before the focus event is processed). However, it gives a convenient, if imperfect, layer of security to keep the reader out of protected fields.
<FORM onSubmit="return false">
    <INPUT TYPE='TEXT' NAME='F1' VALUE='Text'>
</FORM><br>
<FORM onSubmit="return false">
    <INPUT TYPE='TEXT' NAME='F1' 
        onFocus="this.blur();this.value='';document.forms[0].F1.focus();document.forms[0].F1.select()">
</FORM>
Copyright ©1998 by Charles River Media, All Rights Reserved